﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.getsector" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;

namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class getsector : SIPO.Web.BaseHandler
    {
        recSectorRepo recSectorDal = new recSectorRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        string MethodName = string.Empty;
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];

            if (MethodName == "aksikorporasi")
            {
                List<recSector> sectors = recSectorDal.GetList();
                //var result = sectors.Where(x=>x.SectorCode=="2");

                var result = sectors;
                
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
            else if (MethodName == "getbyid")
            {
                int id = Convert.ToInt32(context.Request.Params["sector_id"]);
                List<recSector> sectors = recSectorDal.GetList();
                var result = sectors.Where(x=>x.SectorID==id);

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
            else if (MethodName == "getbysubsubsectorIDs")
            {
                string subsubsectorids = context.Request.Params["subsubsectorids"];
                List<recSector> sectors = recSectorDal.GetListBySubSubSectorIDs(subsubsectorids);

                var result = sectors;
                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
            else if (MethodName == "getsubsubsectorIDsLogin")
            {

                List<recSector> sectors = recSectorDal.GetListBySubSubSectorIDs(base.SubSubSectorIDs);
                var result = sectors;

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
            else
            {
                List<recSector> sectors = recSectorDal.GetList();
                var result = sectors;

                context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
            }
        }
        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}